package com.qianli.cashmama.trade.domain.model;

import com.qianli.cashmama.trade.domain.StateMachine;

import java.io.Serializable;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2017/7/20
 * Time: 下午4:41
 */
public abstract class BaseModel implements Serializable {
    private static final long serialVersionUID = 4834482337025083014L;

    /**
     * 一致性检查
     * 包含各种状态检查 和金额检查
     */
    public void consistencyCheck() {
        statusCheck();

        amountCheck();
    }

    public void transferStatus(String action, int targetStatus,
                               String operator, Date operationDt, Date bizDt,
                               String memo) {
        doTransferStatus(action, targetStatus, operator, operationDt, bizDt, memo);
    }

    /**
     * 状态检查
     */
    protected void statusCheck() {

    }

    /**
     * 金额检查
     */
    protected void amountCheck() {

    }

    /**
     * 状态机签转逻辑
     *
     * @param action
     * @param targetStatus
     * @param operator
     * @param operationDt
     * @param bizDt
     * @param memo
     */
    protected abstract void doTransferStatus(String action, int targetStatus,
                                             String operator, Date operationDt, Date bizDt,
                                             String memo);

    /**
     * 获取交易状态机
     *
     * @return
     */
    protected abstract StateMachine getStatusMachine();

}
